<!--
    模板文件

    author Yuanao
    date 2021年11月11日19:25:45
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>在线预约</title>

    <!-- css -->
    <link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="/plugins/cubeportfolio/css/cubeportfolio.min.css">
    <link href="/css/nivo-lightbox.css" rel="stylesheet"/>
    <link href="/css/nivo-lightbox-theme/default/default.css" rel="stylesheet" type="text/css"/>
    <link href="/css/owl.carousel.css" rel="stylesheet" media="screen"/>
    <link href="/css/owl.theme.css" rel="stylesheet" media="screen"/>
    <link href="/css/animate.css" rel="stylesheet"/>
    <link href="/css/style.css" rel="stylesheet">

    <!-- boxed bg -->
    <link id="bodybg" href="/bodybg/bg1.css" rel="stylesheet" type="text/css"/>
    <!-- template skin -->
    <link id="t-colors" href="/color/default.css" rel="stylesheet">
    <!--    -->
    <script src="/js/pageWriteHtml.js" charset="UTF-8"></script>
    <style>
        form {
            width: 500px;
            margin: 200px auto;
            padding: 20px;
            background-color: white;

        }
        form > h1 {
            text-align: center;
        }
    </style>
</head>

<body id="page-top" data-spy="scroll" data-target=".navbar-custom">

<div id="wrapper">

    <!--  将头部信息写入到这里  -->
    <script>writeHtmlAsHead();</script>


    <form>
        <h1>登 录</h1>
        <div class="form-group">
            <label for="id">用户ID</label>
            <input type="number" class="form-control" id="id" name="" placeholder="请输入用户ID"/>
            <small id="idHelp" class="form-text text-muted"></small>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码">
        </div>
        <div style="height: 1em"></div>
        <button id="login" type="button" class="btn btn-success">登 录</button>
        <button id="register" type="button" class="btn btn-info">注 册</button>
    </form>



    <!--  将头部信息写入到这里  -->
    <script>writeHtmlAsFooter();</script>


</div>
<a href="#" class="scrollup"><i class="fa fa-angle-up active"></i></a>

<!-- Core JavaScript Files -->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/jquery.easing.min.js"></script>
<script src="/js/wow.min.js"></script>
<script src="/js/jquery.scrollTo.js"></script>
<script src="/js/jquery.appear.js"></script>
<script src="/js/stellar.js"></script>
<script src="/plugins/cubeportfolio/js/jquery.cubeportfolio.min.js"></script>
<script src="/js/owl.carousel.min.js"></script>
<script src="/js/nivo-lightbox.min.js"></script>
<script src="/js/custom.js"></script>
<script src="/contactform/contactform.js"></script>


<script>

    //说明:获取url参数
    //参数obj:访问路径
    //返回值:参数
    var url = getQueryString("url");
    if (url == null || url == undefined) {
        url = "";
    }
    url = decodeURIComponent(url);  //url解码

    /**
     * 获取 参数
     *
     * @param name
     * @returns {string|null}
     */
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r !== null)
            return unescape(r[2]);
        return null;
    }





    //登录按钮的点击事件
    $("#login").on("click",function (event) {
        let $id = $("#id");
        let $password = $("#password");

        let id = $id.val();
        let password = $password.val();

        if (id == "" || password == "") {
            alert("请输入用户ID和密码")
            return;
        }

        //发送网络请求,异步登录
        $.post("http://localhost:8080/api/user/login",{
            id:id,
            password:password
        },(data,status)=>{

            console.log(data)

            if (status === "success" && data.code === 0) {
                //将数据存入本地存储中
                localStorage.setItem("user", JSON.stringify(data.data));
                alert("登录成功");
                if (url == "") {
                    url = "/index.html";
                }
                document.location = url;  //回到打开的页面
            } else {
                alert("登录失败,请重试")
            }
        });

    })

    //注册按钮的点击事件
    $("#register").on("click",function (event) {
        document.location = "register.html";
    })
    
    
</script>

</body>

</html>
